
(function () {
    // var LODOP; // 声明为全局变量
    var list_indes = 20;
    var table_left = 5;
    var tab_style = "";
    var tab_begin = "";
    var tab_end = "";
    // var thead = "";
    // var tfooter = "";
    var printhtml = "";
    var printhtml_temp = "";
    var feeprintLeft;
    var feeprintFontTitleFontWidth;
    var TABLE_Width = 160;// table宽度
    var TABLE_HEAD = 25;// 标题高度
    var TABLE_HEIGHT = 0;
    var TABLE_TR = 35;// table行高度
    var dataLenth = 0;
    var dataTable = "";
    // var title = '护理佳纸业产品合格证';//票据温馨提示

    tab_style = "<style>td,th{border:1px solid #000;}</style>";
    tab_begin = "<table border='0'  cellpadding='5' style='border:solid 0 #000000;border-collapse:collapse; font-size:16px;font-weight: bold; flont-family:微软雅黑;text-align:center; width:330px '>";
    thead = "<thead></thead>";
    tfooter = "<tfoot></tfoot>";
    tab_end = "</table>";

    function WarnPrint(data) {
        LODOP.PRINT_INIT(data.title);
//        CreatePage(data);
//var head = data.headDetail;
var html ='<div class="container"><div class="form-group">'+
 '<div class="form-group"><label for="number"  class="number">发货单号:</label><label  type="text" class="form-control" name="number"  style="width:33%;">'+data.fhdh+"            "+'</label><lable type="text" class="form-control city" name="city">杭州</lable></div>'
+'<div class="form-group"><label for="receiptUnit">收货单位:</label><label type="text" class="form-control" name="receiptUnit" >'+data.shdw+'</label></div>'
+'<div class="form-group"><label for="receiptUnit">收货地址:</label><label type="text" class="form-control" name="receiptUnit" >'+data.shdz+'</label></div>'
+'<div class="form-group"><label for="contacts"  class="contacts">联 系 人:</label><label type="text" class="form-control contact-input" name="contacts" placeholder="请输入姓名">'+data.lxr+'</label></div>'
+'<div class="form-group"><label for="telephone" style="line-height:30px;">电    话:</label><lable type="text" class="form-control" name="telephone" placeholder="请输入电话" style="line-height:30px;">'+data.tel+'</label></div>'
+'<div class="form-group"><lable type="text" class="form-control piecesNum" name="piecesNum" placeholder="52-36件"></lable><label class="note">冷藏物品请尽快派送</label></div>'
+'<div class="form-group"><label for="date" style="line-height:30px;">日    期:</label><lable type="text" class="form-control" name="date" placeholder="请输入日期" style="line-height:30px;">'+data.time+'</label></div>'
+'<div class="form-group"><label for="deliveryUnit">发货单位:</label><lable  class="form-control" style="line-height:40px;">郑州安图生物工程股份有限公司</label></div>'
+'</div>'+'</div>'
+'<div id="productList"></div>'

        LODOP.ADD_PRINT_HTM(10,10,"100%","100%",html);

        for (var i = 0; i < data.size; i++) {
        if(i==0){
        LODOP.ADD_PRINT_TEXT(200 , 10, 300, 15,data.cp0+"  ("+data.model0+")");
        LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

        LODOP.ADD_PRINT_TEXT(220 , 10, 300, 15,data.batch0+"     "+data.fqty0);
        LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        }else if(i==1){
        LODOP.ADD_PRINT_TEXT(240 , 10, 300, 15,data.cp1+"  ("+data.model1+")");
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

                LODOP.ADD_PRINT_TEXT(260 , 10, 300, 15,data.batch1+"     "+data.fqty1);
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        }else if(i==2){
        LODOP.ADD_PRINT_TEXT(280 , 10, 300, 15,data.cp2+"  ("+data.model2+")");
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

                LODOP.ADD_PRINT_TEXT(300 , 10, 300, 15,data.batch2+"     "+data.fqty2);
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        }else if(i==3){
        LODOP.ADD_PRINT_TEXT(320 , 10, 300, 15,data.cp3+"  ("+data.model3+")");
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

                LODOP.ADD_PRINT_TEXT(340 , 10, 300, 15,data.batch3+"     "+data.fqty3);
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        }else if(i==4){
        LODOP.ADD_PRINT_TEXT(360 , 10, 300, 15,data.cp4+"  ("+data.model4+")");
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

                LODOP.ADD_PRINT_TEXT(380 , 10, 300, 15,data.batch4+"     "+data.fqty4);
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        }else if(i==5){
        LODOP.ADD_PRINT_TEXT(400 , 10, 300, 15,data.cp5+"  ("+data.model5+")");
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

                LODOP.ADD_PRINT_TEXT(420 , 10, 300, 15,data.batch5+"     "+data.fqty5);
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        }else if(i==6){
        LODOP.ADD_PRINT_TEXT(440 , 10, 300, 15,data.cp6+"  ("+data.model6+")");
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

                LODOP.ADD_PRINT_TEXT(460 , 10, 300, 15,data.batch6+"     "+data.fqty6);
                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        }




        }

//        for(int i=0;i<data.size;i++){
//                LODOP.ADD_PRINT_TEXT(180 , 10, 300, 15,+data.(cpmc+i)+"  "+data.(batch+i));
//                LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
//                LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
//                LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
//                LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
//        }

//        LODOP.SET_PRINT_PAGESIZE(1, 1000, 1500, "");//这里3表示纵向打印且纸高“按内容的高度”；1000表示纸宽100mm；
        // LODOP.PRINT_DESIGN();
        LODOP.PREVIEW();
    }


//function setValue(value) {
//            var html = "";
//            for (var i = 0; i < value.length; i++) {
//                html += '<tr><div class="left"><td class="a">' + "asdf" + '</td><br><td>' + "asdf" + '</td><td>' + "asdf" + '</td><td>' + "asdf" + '</td></div><div class="right"><td>' + "asdf" + '</td></div></tr>'
//            }
//            return html;
//        }

//     document.getElementById("productList").innerHTML = "fas";

    function CreatePage(data) {
        pt = new PrintTemp(data);
        printhtml_temp = printhtml + pt.render();
        printhtml += pt.render();
        dataTable = tab_style + tab_begin + "<tbody>" + printhtml
            + "</tbody>" + tab_end;
        initTable(data);
        LODOP.NewPage();
        LODOP.ADD_PRINT_TABLE(list_indes + 30, table_left, TABLE_Width, TABLE_HEIGHT, dataTable);
        printhtml = "";
        feeprintLeft = (1245 - feeprintFontTitleFontWidth) / 2 + 30;
        if ((feeprintLeft + feeprintFontTitleFontWidth) > 1145) {
            feeprintLeft = 1245 - feeprintFontTitleFontWidth + 30;
        }
//        LODOP.ADD_PRINT_LINE(6, 2, 6, 345, 0, 1);
        // LODOP.ADD_PRINT_TEXT(10, table_left, 200, 18, title);
        LODOP.ADD_PRINT_TEXT(15, 49, feeprintFontTitleFontWidth, 15, data.title);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 20);
        LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
        LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);//内容在打印项中水平居中
        LODOP.SET_PRINT_STYLEA(0, "Horient", 2);//打印项在纸张位置水平居中

        // LODOP.ADD_PRINT_LINE(TABLE_HEIGHT+ list_indes, 2, TABLE_HEIGHT+ list_indes, 345, 0, 1);

        LODOP.ADD_PRINT_TEXT( 18+TABLE_HEIGHT+ list_indes, 15, 200, 15, "开卷方向：");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 15);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

        LODOP.ADD_PRINT_IMAGE(10+TABLE_HEIGHT + list_indes+5, table_left + 100, 240, 25, "<img border='0' src='"+data.opendirection+"' width='240' height='25'/>");

        LODOP.ADD_PRINT_BARCODE(50 + TABLE_HEIGHT + list_indes, table_left + 5, 120, 120, "QRCode", data.qrcode);

for (var i = 0; i < 3; i++) {
LODOP.ADD_PRINT_TEXT(60+i*20 + TABLE_HEIGHT + list_indes, table_left + 130, 300, 15,"地址："+data.address);
        LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
        LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
}
//        LODOP.ADD_PRINT_TEXT(60 + TABLE_HEIGHT + list_indes, table_left + 130, 300, 15,"地址："+data.address);
//        LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
//        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
//        LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
//        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);

//        LODOP.ADD_PRINT_TEXT(80 + TABLE_HEIGHT + list_indes, table_left + 130, 300, 15, "传真："+data.tax);
//        LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
//        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
//        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
//
//        LODOP.ADD_PRINT_TEXT(100 + TABLE_HEIGHT + list_indes, table_left + 130, 300, 15, "电话："+data.phone);
//        LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
//        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
//        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
//
//        LODOP.ADD_PRINT_TEXT(120 + TABLE_HEIGHT + list_indes, table_left + 130, 300, 15, "官方网址："+data.web);
//        LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
//        LODOP.SET_PRINT_STYLEA(0, "FontSize", 10);
//        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
//
//        LODOP.ADD_PRINT_TEXT(145 + TABLE_HEIGHT + list_indes, table_left + 130, 300, 15, data.code);
//        LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
//        LODOP.SET_PRINT_STYLEA(0, "FontSize", 15);
//        LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
    }

    function initTable(data) {
        var fontlength = parseInt(data.title.length) + 4;
        var fontwidth = 7.381 * fontlength;
        feeprintFontTitleFontWidth = fontwidth * 3.057;
        TABLE_HEIGHT = TABLE_TR * 10;
    }

    var PrintTemp = function (data) {
        var me = this;
        var ftl = "";
        var tr_rows_tfoot = "";
        var tr_rows = "";
        var bg_rows = "";

        tr_rows += '<div class="container"><div class="form-group">'+
                              '<div class="form-group"><label for="number"  class="number">发货单号</label><input type="text" class="form-control" name="number" placeholder="00148858" style="width:33%;"><input type="text" class="form-control city" name="city" placeholder="杭州"></div>'
                   +'<div class="form-group"><label for="receiptUnit">收货单位</label><input type="text" class="form-control" name="receiptUnit" placeholder="杭州佰易生物技术有限公司"></div>'
                   +'<div class="form-group"><label for="contacts"  class="contacts">联系人</label><input type="text" class="form-control contact-input" name="contacts" placeholder="请输入姓名"></div>'
                   +'<div class="form-group"><label for="telephone" style="line-height:30px;">电话</label><input type="text" class="form-control" name="telephone" placeholder="请输入电话" style="line-height:30px;"></div>'
                   +'<div class="form-group"><input type="text" class="form-control piecesNum" name="piecesNum" placeholder="52-36件"><label class="note">冷藏物品请尽快派送</label></div>'
                   +'<div class="form-group"><label for="date" style="line-height:30px;">日期</label><input type="text" class="form-control" name="date" placeholder="请输入日期" style="line-height:30px;"></div>'
                   +'<div class="form-group"><label for="deliveryUnit">发货单位</label><p  class="form-control" style="line-height:40px;">郑州安图生物工程股份有限公司</p></div>'
                   +'</div>'+'</div>'
                   +'<div id="productList"></div>';

        bg_rows = tr_rows + tr_rows_tfoot;
        ftl = bg_rows;
        me.render = function () {
            var render = template.compile(ftl);
            template.helper('getVal', function (v) {
                if (v) {
                    return v;
                } else {
                    return "-";
                }
            });
            template.helper('getSize', function (v) {
                if (v.length > 15) {
                    return 10;
                } else {
                    return 13;
                }
            });
            return render({
                bills: data.items
            });
        };
    }
    window.WarnPrint = WarnPrint;
})();
